home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 132_01 / shoot1.c < prev    next >
Text File  |  1985-08-19  |  7KB  |  353 lines

  1.     #ASM
  2.     ORG    4000H
  3.     LIST    -L
  4.     #ENDASM
  5.     #INCLUDE    GRAPH.H
  6.     #INCLUDE    SHOOT.H
  7.     #INCLUDE    PRELUDE
  8. /*
  9.     allocate list storage
  10. */
  11. int    master[NMASTER];
  12. int    lpage0[NPAGE],lpage1[NPAGE];
  13. int    toggle;    /* a toggle for page flipping */
  14. char    *prx,*pry;    /* right x and y joystick pointers */
  15. int    score;
  16. shoot()
  17. {
  18. int    *scrn,n,xr,yr,*object;
  19. int    *mscan;
  20.     prx = JOYRX;
  21.     pry = JOYRY;
  22.  
  23. *flop = 2;    /* clock interrupt counter = 2 */
  24. toggle = 0;
  25. score = 0;
  26. xr =1;
  27. yr = 1;
  28. init();        /* set up the graphics lists */
  29. while(1) {
  30.     if(firer())    {
  31.         remclk();
  32.         return;        /* exit */
  33.     }
  34.     if(procedure(master)==EOF) break; /* object procedure update */
  35.     display();
  36.     }
  37. }
  38. /*
  39.     procedure(plist)    scans a linked list of graphics records
  40. the head of which is pointed to by plist. If the object is not blanked
  41. (active) and the procedure pointer is not = NULL, the procedure at the 
  42. address in the list will be executed. Eof is returned if there is an
  43. error in procedure(plist), Null otherwise.
  44. */
  45. procedure(plist)
  46. int    *plist;
  47. {
  48.     int    flag;
  49.     
  50.     flag  = NULL;
  51.     while(1) {
  52.         if((plist[FLAGS] & BLANKED)==NULL)  { /* if object is active */ 
  53.             if(plist[PROC] !=NULL) { /* and has a procedure defined */
  54.         if((flag = prcall(master,plist,plist[PROC])) == EOF) break;
  55.             }
  56.         }
  57.         plist = plist[FORWARD];
  58.         if(plist == NULL) break;
  59.     }
  60.     return(flag);
  61. }
  62. /*
  63.     prcall(x,y,z,...addr) jumps to the address passed on the stack.
  64.     Multiple parameters may be passed if addr is the last. Return is
  65.     via the called subroutine.
  66. */
  67. prcall(addr)
  68. int     *addr;
  69. {
  70.     #ASM
  71.     JMP    [2,S]
  72.     #ENDASM
  73. }
  74. display()    /* display the next page */
  75. {
  76.     if(toggle) {
  77.         cwriter(UPPG0,master,lpage0,PAGE0);
  78.         toggle = 0;
  79.         while(*flop != NULL); /* wait for page flip time */
  80.         *flop = NTICKS;
  81.         setscrn(PAGE0);
  82.     }
  83.     else {
  84.         cwriter(UPPG1,master,lpage1,PAGE1);
  85.         toggle = 1;
  86.         while(*flop != NULL);
  87.         *flop = NTICKS;
  88.         setscrn(PAGE1);
  89.     }
  90. }
  91. release(objnum,x,y,vx,vy) /* set object in position with velocity */
  92. int    objnum,x,y,vx,vy;
  93. {
  94. int    *loc;
  95.     if((loc=locate(master,objnum))==NULL) return(-1);/* error */
  96.     loc[X]=x;
  97.     loc[Y]=y;
  98.     loc[XINCR]=vx;
  99.     loc[YINCR]=vy;
  100.     loc[FLAGS] = MOVER | UPALL;
  101.     return(NULL);
  102. }
  103. move(objnum)    /* move the specified object */
  104. int    objnum;
  105. {
  106. int    *loc;
  107.     if((loc=locate(master,objnum))==NULL) return(-1);
  108.     loc[X]= loc[X] + loc[XINCR];
  109.     loc[Y] = loc[Y] + loc[YINCR];
  110.     loc[FLAGS] = loc[FLAGS] | UPALL;
  111. }
  112. firel()    /* test the state of left fire button. Return 1 if on */
  113. {
  114. char    *pstate;
  115.     pstate = SWPORT;
  116.     if(((*pstate)&SWTR) != NULL) return(NULL);
  117.     else      return(1);
  118. }
  119. firer()
  120. {
  121. char    *pstate;
  122.     pstate = SWPORT;
  123.     if(((*pstate)&SWTL) != NULL) return(NULL);
  124.     else    return(1);
  125. }
  126. blank(objnum)    /* turn off (blank) an object */
  127. int    objnum;
  128. {
  129. int     *loc;
  130.     if((loc=locate(master,objnum)) == NULL) return(-1);
  131.     loc[FLAGS] = BLANKED | UPALL;
  132.     return(NULL);
  133. }
  134. blanked(objnum)    /* TESTS for object blanked */
  135. int    objnum;
  136. {
  137. int    *loc;
  138.     if((loc=locate(master,objnum)) == NULL)return(1);
  139.     return((loc[FLAGS])&BLANKED);
  140. }
  141. posx(objnum)
  142. int    objnum;
  143. {
  144. int    *loc;
  145.     if((loc=locate(master,objnum)) == NULL)return(-1);
  146.     return(loc[X]);
  147. }
  148. posy(objnum)
  149. int    objnum;
  150. {
  151. int    *loc;
  152.     if((loc=locate(master,objnum)) == NULL) return(-1);
  153.     return(loc[Y]);
  154. }
  155. hit(proj,targ)
  156. int    proj,targ;
  157. {
  158. int    *pproj,*ptarg;
  159.     if((pproj=locate(master,proj)))
  160.         if((ptarg=locate(master,targ))) {
  161.             return(overlap(pproj,ptarg));
  162.         }
  163.     return(NULL);
  164. }
  165. replace(oldobj,newobj)    /* change the displayed object to the selected one */
  166. int    oldobj,newobj;
  167. {
  168. int    *from,*to;
  169.     if((from=locate(master,oldobj)))
  170.         if((to=locate(master,newobj))){
  171.             from[FLAGS]=BLANKED | UPALL ;
  172.             to[FLAGS] = UPALL;
  173.             to[X]=from[X];
  174.             to[Y]=from[Y];
  175.             to[XINCR]=from[XINCR];
  176.             to[YINCR]=from[YINCR];
  177.             return(NULL);
  178.         }
  179.     return(-1);
  180. }
  181. locate(plist,objnum)
  182. int    *plist,objnum;
  183. {
  184.     while(plist[FORWARD] != NULL) {
  185.         if(plist[NUMBER] != objnum) {
  186.             plist = plist[FORWARD];
  187.         }
  188.         else    return(plist);
  189.     }
  190.     return(NULL);
  191. }
  192. /*
  193.     test procedure for airplane
  194. */
  195. pplane(mlist,plist,proc)
  196. int    *mlist,*plist,*proc;
  197. {
  198.     plist[X] = plist[X] + 1;
  199.     if(plist[X] > PLNXM) {
  200.         plist[FLAGS] = BLANKED | UPALL ;
  201.     }
  202.     else {
  203.         plist[FLAGS] = plist[FLAGS] | UPALL;
  204.     }
  205.     return(NULL);
  206. }
  207. pgun(mlist,plist,proc)
  208. int    *mlist,*plist,*proc;
  209. {
  210. int    vx,vy,x,y ;
  211.  
  212.     x = plist[X];
  213.     y = plist[Y];
  214.     vx = deadzn(*prx);
  215.     vy = deadzn(*pry);
  216.     y  = y + (vy << 1);
  217.     x  = x + (vx << 1);
  218.     bound(plist,0,0,GUNXMX,GUNYMX);
  219.     if(blanked(BULLET)) 
  220.         if(firel()) 
  221.             release(BULLET,x,y,vx * 3,vy * 3);
  222.     plist[X] = x;
  223.     plist[Y] = y;
  224.     plist[FLAGS] = plist[FLAGS] | UPALL;
  225.     return(NULL);
  226. }
  227. pbullet(mlist,plist,proc)
  228. int    *mlist,*plist,*proc;
  229. {
  230. int    *phit, *ptr;
  231.  
  232.     plist[X] = plist[X] + plist[XINCR];
  233.     plist[Y] = plist[Y] + plist[YINCR];
  234.     if(phit=ovlclas(plist,TARGET)) {
  235.         plist[FLAGS] = BLANKED;
  236.         score++;
  237.         replace(phit[OBJNUM],BOOM);
  238.         if(ptr = locate(mlist,BOOM)) {
  239.             ptr[PROC] = pdelay;
  240.             ptr[COUNT] = 60;
  241.         }
  242.     }
  243.     else if(bound(plist,0,0,BULXMX,BULYMX))
  244.         plist[FLAGS] = BLANKED;
  245.     plist[FLAGS] = plist[FLAGS] | UPALL;
  246.     return(NULL);
  247. }
  248. deadzn(val)
  249. char    val;
  250. {
  251. int    v;
  252.     v = 0;
  253.     if(val < JOYMIN) v = -1;
  254.     else if(val > JOYMAX) v = +1;
  255.     return(v);
  256. }
  257. bound(pobj,xmin,ymin,xmax,ymax)
  258. int    *pobj,xmin,ymin,xmax,ymax;
  259. {
  260. int    retval,x,y;
  261.  
  262.     retval = NULL;
  263.     x =pobj[X];
  264.     y = pobj[Y];
  265.     if(x < xmin) { x = xmin;
  266.             retval = 1;
  267.     }
  268.     else if(x > xmax){
  269.         x = xmax;
  270.         retval = 1;
  271.     }
  272.     if(y < ymin) {
  273.         y = ymin;
  274.         retval = 1;
  275.     }
  276.     else if(y >ymax) {
  277.         y = ymax;
  278.         retval = 1;
  279.     }
  280.     pobj[X] = x;
  281.     pobj[Y] = y;
  282.     return(retval);
  283. }
  284. ovlclas(pobj,mlist,class)
  285. int    *pobj,*mlist,class;
  286. {
  287. int    *ptr;
  288.  
  289.     ptr = NULL;
  290.     while(1) {
  291.         if(mlist != pobj)
  292.             if(mlist[CLASS] == class)
  293.                 if(overlap(pobj,mlist)) {
  294.                     ptr = mlist;
  295.                     break;
  296.                 }
  297.         if((mlist=mlist[FORWARD]) == NULL) break;
  298.     }
  299.     return(ptr);
  300. }
  301. pdelay(mlist,plist,proc)
  302. int    *mlist,*plist,*proc;
  303. {
  304. if(--(plist[COUNT]) <= 0)
  305.     plist[FLAGS] = BLANKED | UPALL;
  306. return(NULL);
  307. }
  308. pchase(mlist,plist,proc)
  309. int    *mlist,*plist,*proc;
  310. {
  311.     int    x,y,deltx,delty,*temp ;
  312.  
  313.     x = plist[X];
  314.     y = plist[Y];
  315.     deltx = 0;
  316.     delty = 0;
  317.     if((temp = locate(mlist,GUN)) == NULL) return(EOF);
  318.     if((x - temp[X]) > 0) deltx = -1;
  319.     if((x - temp[X]) < 0) deltx =1;
  320.     if((y - temp[Y]) > 0) delty = -1;
  321.     if((y - temp[Y]) < 0) delty = 1;
  322.     plist[X] = x + deltx;
  323.     plist[Y] = y + delty;
  324.     if(overlap(plist,temp)) {
  325.         temp[PROC] = NULL; /* kill future updates */
  326.         replace(GUN,BOOM);
  327.         plist[FLAGS] = BLANKED;
  328.     }
  329.     plist[FLAGS] = plist[FLAGS] | UPALL ;
  330.     return(NULL);
  331. }
  332. cwriter(upflag,mlist,page,screen)
  333. int    upflag,*mlist,*page,*screen;
  334. {
  335.  
  336.  
  337.     pass0(upflag,mlist,page,screen);
  338.     pass2(mlist,page,screen);
  339. }
  340.     #INCLUDE    shootini.c
  341.     #INCLUDE    SHOOT.GPH
  342.     #ASM
  343.     ORG    06800H
  344.     #ENDASM
  345.     #INCLUDE    fpass0.c
  346.     #INCLUDE    fpass1.c
  347.     #INCLUDE    fpass2.c
  348.     #INCLUDE    LIB
  349.     #INCLUDE    RUN
  350.     #ASM
  351.     LIST    *
  352.     #ENDASM
  353.